<template>
<view class="container">
    <view class="header">
        <view class="header_top">
            <view class="header_left width100">
                <view>余额</view>
                <view>{{info.money}}</view>
                <view @click="take" v-if="role == 2 || role == 4" class="tx">提现</view>
				<!-- <view @click="take" class="tx">提现</view> -->
            </view>
			
			<view class="header_center width100">
				<image :src="info.avatar"></image>
				<view>{{info.nickname}}</view>
				<view v-if="role==1">[用户]</view>
				<view v-if="role==2">[会员]</view>
				<view v-if="role==3">[机构]</view>
				<view v-if="role==4">[合伙人]</view>
			</view>
			<view class="header_left width100" v-if="role ==3">
				<view>简历份数</view>
				<view>{{seeNum}}</view>
				<view @click="jump('/pages/vip/index')" class="tx">购买</view>
				<view @click="rulesee" class="headerrule">积分余额规则</view>
			</view>
			<view class="header_left width100" v-else="role">
				<view>积分余额</view>
				<view>{{info.integral}}</view>
				<view @click="rulesee" class="headerrule">积分余额规则</view>
			</view>
        </view>
    </view>
	<view class="subscribe" v-if="role == 3">
		<view v-if="CompanyStatus == 1" class="message">店铺状态:正在营业..</view>
		<view v-else class="message">店铺状态:正在转让..</view>
		<view v-if="CompanyStatus == 1" class="leaseButtom" @click="lease(2)">店铺转租</view>
		<view v-else class="leaseButtomFalse" @click="lease(1)">取消转租</view>
	</view>
	<view class="subscribe" v-if="subscribe">
		<view class="message">关注公众号,可进行提现,获取服务通知</view>
		<button class="contact" @click="jump('/pages/user/wxRcode/index')">关注</button>
	</view>
	
	<view class="buy" v-if="role == 3">
		<view class="buy_item border_right" @click="jump('/pages/vip/index')">
			<image src="/static/icon/vipbuy.png"></image>
			<text>购买简历</text>
		</view>
		<view class="buy_item border_right" @click="buy()">
			<image src="/static/icon/vipsend.png"></image>
			<text>群发助手</text>
		</view>
		<view class="buy_item border_right" @click="push()">
			<image src="/static/icon/vippush.png"></image>
			<text>推荐人才</text>
		</view>
	</view>
		
	<view class="content">
		<!--第一行公共全部都可以用-->
		<view class="row">
			<view class="row_init border_right" @click="jumpCenter('/pages/user/money/money')">
				<image src="/static/img1/money.png"></image>
				<view class="row_init_content">
					我的收益
				</view>
			</view>
			<view class="row_init border_right" @click="jumpCenter('/pages/user/money/index')">
				<image src="/static/img1/score1.png"></image>
				<view class="row_init_content">
					我的积分
				</view>
			</view>
			<view class="row_init border_right" @click="jumpCenter('/pages/user/team/index')">
				<image src="/static/img1/share.png"></image>
				<view class="row_init_content">
					我的团队
				</view>
			</view>
		</view>
		<!--第二行未注册-->
		<view class="row" v-if="role == 1">
			<view class="row_init border_right" @click="jumpUser()" v-if="info.role !== 4">
				<image src="/static/img1/info1.png"></image>
				<view class="row_init_content">
					我的信息
				</view>
			</view>
			<view class="row_init border_right" @click="jumpCenter('/pages/user/rcode/index')">
				<image src="/static/img1/rcode.png"></image>
				<view class="row_init_content">
					我的二维码
				</view>
			</view>
		</view>
		
		 <!--第二行个人和机构-->
		<view class="row" v-if="role ==2 || role == 3">
			<view class="row_init border_right" @click="jumpUser()" v-if="role !== 4">
				<image src="/static/img1/info1.png"></image>
				<view class="row_init_content">
					我的信息
				</view>
			</view>
			<view class="row_init border_right" @click="jumpCenter('/pages/user/center/order')">
				<image src="/static/img1/order.png"></image>
				<view class="row_init_content">
					我的订单
				</view>
			</view>
			 <view class="row_init border_right" @click="jumpCenter('/pages/user/center/collection')">
				<image src="/static/img1/sc.jpg"></image>
				<view class="row_init_content">
					我的收藏
				</view>
			</view>
		</view>
		<!--第二行代理商-->
		<view class="row" v-if="role == 4">
			<view class="row_init border_right" @click="jumpCenter('/pages/user/center/take')">
				<image src="/static/img1/tx.png"></image>
				<view class="row_init_content">
					提现记录
				</view>
			</view>
			<view class="row_init border_right" @click="jumpCenter('/pages/user/rcode/index')">
				<image src="/static/img1/rcode.png"></image>
				<view class="row_init_content">
					我的二维码
				</view>
			</view>
		</view>
		<!--第三行个人-->
		<view class="row" v-if="role == 2">
			<view class="row_init border_right" @click="jumpCenter('/pages/user/center/take')">
				<image src="/static/img1/tx.png"></image>
				<view class="row_init_content">
					提现记录
				</view>
			</view>
			<view class="row_init border_right" @click="jumpCenter('/pages/user/rcode/index')">
				<image src="/static/img1/rcode.png"></image>
				<view class="row_init_content">
					我的二维码
				</view>
			</view>
			<!--<view class="row_init border_right" @click="jump('/pages/user/wxRcode/index')">
				<image src="/static/img1/tx.png"></image>
				<view class="row_init_content">
					我的充值
				</view>
			</view>-->
		</view>
		<!--第三行机构-->
		<view class="row" v-if="role == 3">
			<view class="row_init border_right" @click="jumpCenter('/pages/user/center/matchjob')">
				<image src="/static/img1/match.jpg"></image>
				<view class="row_init_content">
					职位匹配
				</view>
			</view>
			<view class="row_init border_right" @click="jumpCenter('/pages/user/center/vip')">
				<image src="/static/img1/vvip.png"></image>
				<view class="row_init_content">
					我的VIP
				</view>
			</view>
			<view class="row_init border_right" @click="jumpCenter('/pages/user/rcode/index')">
				<image src="/static/img1/rcode.png"></image>
				<view class="row_init_content">
					我的二维码
				</view>
			</view>
		</view>
		<!--第四行-->
		<view class="row" v-if="info.id == 3">
			<view class="row_init border_right" @click="jumpCenter('/pages/user/agent/index')">
				<image src="/static/img1/dls.png"></image>
				<view class="row_init_content">
					我的合伙人
				</view>
			</view>
		</view>
		
	</view>
	
	<view class="bqnum">
		<view>版权号:2021SR0986644</view>
		<view>版权所有:天意美业直通车(天津)网络科技有限公司</view>
	</view>
	<view class="scoreRule" v-if="ruleShow">
	    <view class="ruleContent">
	        <image class="close" @click="ruleShow = false" src="/static/img/popup-close.png"></image>
	        <view class="ruleRemark">
				<rich-text v-if="remark" :nodes="remark"></rich-text>
	        </view>
	        <button @click="cancelRule" class="rulrButton">关闭</button>
	
	    </view>
	</view>
	
	<view class="take" v-if="takeShow" @click="takeShow = false">
	   <view class="inner" @click.stop="">
	        <view class="inner_img">
	            <image @click="takeShow = false" src="/static/img/popup-close.png"></image>
	        </view>
	        <view class="inner_title">提现申请</view>
	
	        <view class="inner_content">
	            <view>提现金额</view>
	            <input type="number"  v-model="takeMoney" placeholder="请输入提现金额"></input>
	        </view>
	        <view class="inner_footer" v-if="takeTrue" @click="takeAdd">提交</view>
	   </view>  
	</view>
	
</view>
</template>
<script>
import request from '@/util/request.js'
export default {
	data() {
		return {
			takeShow:false,
			takeTrue:true,
			role:0,
			subscribe:false,
			CompanyStatus:1,
			viewId:0,
			seeNum:0,
			info:{},
			ruleShow:false,
			remark:'',
			takeMoney:''
		}
	},
	onShow:function(){
		this.role = uni.getStorageSync('role')
		if(!uni.getStorageSync('uid')){
			//没有缓存 跳转授权页面
			uni.navigateTo({
				url:'/pages/index/guide'
			})
		}else{
			this.getUserInfo()
		}
	},
	methods:{
		getUserInfo:function(){
			var data ={'uid':uni.getStorageSync('uid')}
			var that = this
			request({
				url: 'member/info',
				method: 'get',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						that.info = res.data.data
						that.role = res.data.data.role
						if(!res.data.data.phone){
							//未注册手机号
							uni.navigateTo({
								url:'/pages/index/phone'
							})
						}else{
							that.getWx();
							//that.viewSave(); 获取活跃度  暂时不获取
							if(res.data.data.role == 3){
								//机构
								that.getCompanyStatus()//商户状态是否转租
								that.getSeeNum();//剩余简历数
							}
							
						}
					}
				},
			})
		},
		getWx:function(){
			var data = {'uid':uni.getStorageSync('uid')}
			var that = this
			request({
				url: 'user/wxUser',
				method: 'get',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						if(res.data.data.subscribe == 2){
							that.subscribe = true
						}
					}else{
						that.subscribe = true
					}
				}
			})
		},
		getCompanyStatus:function(){
			var data = {'uid':uni.getStorageSync('uid')}
			var that = this
			request({
				url: 'company/companyInfo',
				method: 'get',
				data:data,
				success: (res) => {
					//请求成功
					if(res.data.code == 1){
						that.CompanyStatus = res.data.data.is_lease
					}
				}
			})
		},
		getSeeNum:function(){
			var data ={'uid':uni.getStorageSync('uid')}
			var that = this
			request({
				url: 'vip/seeNum',
				method: 'get',
				data:data,
				success: (res) => {
				//请求成功
					if(res.data.code == 1){
						that.seeNum = res.data.data
					}
				}
			})
		},
		lease:function(type){
			var data = {
				is_lease:type,
				uid:uni.getStorageSync('uid')
			}
			var that = this
			request({
				url: 'company/putLease',
				method: 'put',
				data:data,
				success: (res) => {
					//请求成功
					if(res.data.code == 1){
						that.CompanyStatus = type
						uni.showToast({
							title: '成功!!!',
							icon: "success", 
							position:'bottom',
						});
					}
				}
			})
		},
		viewSave:function(){
			var that = this
			var data = {
				uid:uni.getStorageSync('uid')
			}
			request({
				url: 'view/add',
				method: 'get',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						that.viewId = res.data.data
					}
				}
			})
		},
		// onHide:function(){
		// 	var that = this
		// 	var data = {id:this.viewId}
		// request({
		// 	url: 'view/put',
		// 	method: 'put',
		// 	data:data,
		// 	success: (res) => {
		// 	})
		// },
		jump:function(url){
			if(url == '/pages/vip/index'){
				uni.navigateTo({
					url:url
				})
				return;
			}
			plus.share.getServices(
				res => {
					let sweixin = null;
					for (let i in res) {
						if (res[i].id == 'weixin') {
							sweixin = res[i];
						}
					}
					//唤醒微信小程序
					if (sweixin) {
						sweixin.launchMiniProgram({
							id: 'gh_42fb5eed1670', //
							type: 0, //小程序版本  0-正式版； 1-测试版； 2-体验版。
							path: 'pages/index/index' //小程序的页面,用传的参数在小程序接值判断跳转指定页面
						});
					}
				}
			);
		},
		rulesee:function(){
			var data = {'id':1}
			var that = this
			request({
				url: 'rule/info',
				method: 'get',
				data:data,
				success: (res) => {
					that.remark = res.data.data.content
					that.ruleShow = true
				}
			})
		},
		take:function(){
			if(this.subscribe){
				uni.navigateTo({
					url:'/pages/user/wxRcode/index'
				})
				return;
			}else{
				this.takeShow = true
			}
		},
		takeAdd:function(){
			if(!this.takeMoney){
				uni.showToast({
					title: '请输入提现金额!!!',
					icon: "none", 
					position:'bottom',
				});
				return;
			}
			//this.takeTrue = false
			if(parseFloat(this.takeMoney) > this.info.money){
				uni.showToast({
					title: '余额不足!!!',
					icon: "none", 
					position:'bottom',
				});
				return;
			}
			if(parseFloat(this.takeMoney) > 200){
				uni.showToast({
					title: '超过单笔提现限额200!!!',
					icon: "none", 
					position:'bottom',
				});
				return;
			}
			var data = {
				'uid':uni.getStorageSync('uid'),
				'money':this.takeMoney
			}
			var that = this
			request({
				url: 'take/add',
				method: 'post',
				data:data,
				success: (res) => {
					that.takeTrue = true
					if(res.data.code == 1){
						uni.showToast({
							title: '提现申请成功,请等待审核!!!',
							icon: "success", 
							position:'bottom',
						});
						that.info.money = that.info.money - that.takeMoney
						that.takeShow = false
					}else{
						uni.showToast({
							title: res.data.msg,
							icon: "none", 
							position:'bottom',
						});
						return;
					}
				}
			})
		},
		jumpCenter:function(url){
			uni.navigateTo({
				url:url
			})
		},
		jumpUser:function(){
			//未注册
			if(this.role == 1){
				uni.navigateTo({
					url:'/pages/login/index'
				})
			}
			if(this.role == 2){
				uni.navigateTo({
					url:'/pages/user/info/personal'
				})
			}
			if(this.role == 3){
				uni.navigateTo({
					url:'/pages/user/info/company'
				})
			}
		},
		push:function(){
			var data = {
				uid:uni.getStorageSync('uid')
			}
			var that = this
			request({
				url: 'vip/message',
				method: 'get',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						uni.navigateTo({
							url:'/pages/user/push'
						})
					}else{
						uni.showToast({
							title: '白金VIP会员有此权限',
							icon: "success", 
							position:'bottom',
						});
					}
				},
			})
		},
		buy:function(){
			var data = {company_uid:uni.getStorageSync('uid')}
			var that = this
			request({
				url: 'group/num',
				method: 'get',
				data:data,
				success: (res) => {
					if(res.data.data){
						var url = '/pages/user/message?num='+res.data.data.num+'&groupId='+res.data.data.id
					}else{
						var url = '/pages/user/group'
					}
					uni.navigateTo({
						url:url
					})
				},
			})
		}
	}
}
</script>

<style>
	@import url("./css/index.css");
</style>
